import numpy as np
import matplotlib.pyplot as plt

# 配置中文显示
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

# 定义函数


# 创建x值数组（排除奇点附近的区域）
# f_values = np.linspace(0.1, 8, 10000)
# x_vals = np.pi*np.sqrt(f_values)  # 0.1到3.0范围足够展示主要特征
f0=4.4
x = np.linspace(0, 40, 100000)  # 0.1到3.0范围足够展示主要特征

# 计算对应的u值
omega=2*np.pi*x
omega0=2*np.pi*f0
xc = np.sqrt(omega/omega0)*np.pi
numerator = np.cos(xc)/np.sin(xc) - np.cosh(xc)/np.sinh(xc)
denominator = 1/np.sinh(xc)-1/np.sin(xc)

u_vals = np.arccosh(np.abs(numerator / denominator))
# 创建图形
u_vals[np.isnan(u_vals)]=0
plt.figure(figsize=(6,4),dpi=600)
# 绘制函数曲线
u_vals[np.isnan(u_vals)]=0
# plt.plot(x, u_vals, 'b-', linewidth=2)
plt.plot(x, u_vals, 'b-', linewidth=2)
# print(valid_indices)

# 添加标签和标题
plt.xlabel(f'f(f0={f0}Hz)', fontsize=12)
plt.ylabel('u', fontsize=12)
# plt.title('函数: $\cosh(u) = \\frac{\cot(x) - \coth(x)}{\cosech(x) - \cosec(x)}$', fontsize=14)
plt.grid(True, alpha=0.3)

# 设置坐标轴范围
plt.ylim(0,2)
plt.xlim(x.min(), x.max())

# 显示图像
plt.tight_layout()
plt.savefig('beam.png')
